<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Shipping_entity{
	var $id = 0;
	var $user_id = "";
	var $courier_name = "";
	var $status = "";
	var $date = 0;
	
	function __destruct() {}
	function __construct() {}
    
	function init($cmd, $input)
	{
		$ci=& get_instance();
		
		if($cmd == 'user_id')
		{
			$result = $ci->db->where('user_id',$input)->get(TBL_SHIPPING)->result();
		}
		elseif($cmd == 'id')
		{
			$result = $ci->db->where('id',$input)->get(TBL_SHIPPING)->result();
		}
		else
		{
			return false;
		}
		
		if( !empty($result) )
		{
			$this->id = $result[0]->id;
			$this->user_id = $result[0]->user_id;
			$this->courier_name = $result[0]->courier_name;
			$this->status = $result[0]->status;
			$this->date = $result[0]->date;
			
			return $this;
		}
		return false;
	}
	
	function setUserId($input){ $this->user_id=$input; }
	function setCourierName($input){ $this->courier_name=$input; }
	function setStatus($input){ $this->status=$input; }
	function setDate($input){ $this->date=$input; }
	
	function getId(){ return $this->id; }
	function getUserId(){ return $this->user_id; }
	function getCourierName(){ return $this->courier_name; }
	function getStatus(){ return $this->status; }
	function getDate(){ return $this->date; }
	
	function update()
	{
		$ci=& get_instance();
		 
		$ci->db->set('user_id', $this->user_id);
		$ci->db->set('courier_name', $this->courier_name);
		$ci->db->set('status', $this->status);
		$ci->db->set('date', $this->date);
		
		$ci->db->where('id', $this->id)->update(TBL_SHIPPING);
	}
	
	function createNewEntity(){
		$ci=& get_instance();
		$ci->db->set('date', time());
		$ci->db->insert(TBL_SHIPPING);
		
		return $ci->db->insert_id();
	}
	
	
}
